package com.baizhi.service.ServiceImpl;

import com.baizhi.annotation.LogAnnotation;
import com.baizhi.dao.AlbumDao;
import com.baizhi.entity.Album;
import com.baizhi.service.AlbumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/4/7.
 */
@Service
public class AlbumServiceImpl implements AlbumService {
    @Autowired
    AlbumDao albumDao;

    @Override
    @LogAnnotation("查询所有哦的专辑")
    public Map selectAllAlbum(int rows, int page, String albumName) {
        Map map=new HashMap();
        if(albumName!=null){
            if("".equals(albumName)){
                albumName=null;
            }else{
                albumName="%"+albumName+"%";
            }
        }
        int begin=rows*(page-1);
        int size=rows;
        Integer count=albumDao.selectAllAlbumCount(albumName);
        List<Album> users=albumDao.selectAllAlbum( begin,size,albumName);

        map.put("total",count);
        map.put("rows",users);
        return map;
    }

    @Override
    public Map delatebanner(Integer[] ids) {
        Map map=new HashMap();
        try {
            albumDao.delateAlbum(ids);
            map.put("isok",true);
        } catch (Exception e) {
            map.put("isok",false);
        }
        return  map;
    }

    @Override
    public Map updateBanner(Album album) {
        Map map=new HashMap();
        try {
            albumDao.updateAlbum(album);
            map.put("isok",true);
        } catch (Exception e) {
            map.put("isok",false);
        }
        return  map;
    }

    @Override
    public Map addAlbum(Album album) {
        Map map=new HashMap();
        try {
            albumDao.addAlbum(album);
            map.put("isok",true);
        } catch (Exception e) {
            map.put("isok",false);
        }
        return  map;
    }

    @Override
    public Map appselectAllAlbum() {
        Map map=new HashMap();
        List<Album> albums=albumDao.appselectAllAlbum();
        map.put("albums",albums);
        return map;
    }
}
